<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:system="clr-namespace:System;assembly=mscorlib"
                    xmlns:wpf="clr-namespace:MaterialDesignThemes.Wpf;assembly=MaterialDesignThemes.Wpf"
                    xmlns:converters="clr-namespace:MaterialDesignThemes.Wpf.Converters;assembly=MaterialDesignThemes.Wpf">

    <converters:BooleanToVisibilityConverter x:Key="BoolToVisConverter"/>
    <converters:BooleanToVisibilityConverter x:Key="InverseBoolToVisConverter" TrueValue="Collapsed" FalseValue="Visible"/>
    <converters:RangePositionConverter x:Key="RangePositionConverter"/>
    <converters:MathMultipleConverter x:Key="TranslateConverter" Operation="Multiply"/>
    <system:Double x:Key="NoContentFloatingScale">1.0</system:Double>
    <SineEase x:Key="AnimationEasingFunction" EasingMode="EaseOut"/>

    <Style TargetType="{x:Type wpf:SmartHint}">
        <Setter Property="HorizontalAlignment" Value="Left"/>
        <Setter Property="VerticalAlignment" Value="Bottom"/>
        <Setter Property="HorizontalContentAlignment" Value="Left"/>
        <Setter Property="VerticalContentAlignment" Value="Bottom"/>
        <Setter Property="IsTabStop" Value="False"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type wpf:SmartHint}">
                    <ControlTemplate.Resources>
                        <system:Double x:Key="DisabledOpacity">1</system:Double><!--TextBlock disabled opacity should not be applied on top of HintOpacity-->
                    </ControlTemplate.Resources>
                    <Grid Margin="{TemplateBinding Padding}"
                          HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
                          VerticalAlignment="{TemplateBinding VerticalAlignment}">
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="ContentStates">
                                <VisualStateGroup.Transitions>
                                    <VisualTransition From="*" To="HintFloatingPosition">
                                        <Storyboard>
                                            <DoubleAnimation Storyboard.TargetName="SimpleHintTextBlock" Storyboard.TargetProperty="Opacity"
                                                             Duration="0:0:0" To="0" />
                                        </Storyboard>
                                    </VisualTransition>
                                    <VisualTransition From="*" To="HintRestingPosition">
                                        <Storyboard>
                                            <DoubleAnimation Storyboard.TargetName="SimpleHintTextBlock" Storyboard.TargetProperty="Opacity"
                                                             Duration="0:0:0.3"
                                                             EasingFunction="{StaticResource AnimationEasingFunction}"/>
                                        </Storyboard>
                                    </VisualTransition>
                                </VisualStateGroup.Transitions>
                                <VisualState x:Name="HintFloatingPosition">
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetProperty="Opacity" Storyboard.TargetName="SimpleHintTextBlock"
                                                         Duration="0" To="0" />
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="HintRestingPosition">
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetProperty="Opacity" Storyboard.TargetName="SimpleHintTextBlock"
                                                         Duration="0" />
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <ContentControl x:Name="SimpleHintTextBlock"
                                        IsTabStop="False"
                                        Visibility="{TemplateBinding UseFloating, Converter={StaticResource InverseBoolToVisConverter}}"
                                        Content="{Binding Path=Hint, RelativeSource={RelativeSource TemplatedParent}, UpdateSourceTrigger=PropertyChanged}"
                                        FontSize="{TemplateBinding FontSize}"
                                        HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                        VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                        Opacity="{TemplateBinding HintOpacity}"
                                        IsHitTestVisible="False"/>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Style.Triggers>
            <Trigger Property="UseFloating" Value="True">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type wpf:SmartHint}">
                            <Grid Margin="{TemplateBinding Padding}"
                                  HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
                                  VerticalAlignment="{TemplateBinding VerticalAlignment}">
                                <VisualStateManager.VisualStateGroups>
                                    <VisualStateGroup x:Name="ContentStates">
                                        <VisualStateGroup.Transitions>
                                            <VisualTransition From="*" To="HintFloatingPosition">
                                                <Storyboard>
                                                    <DoubleAnimation Storyboard.TargetName="FloatingHintTextBlock" Storyboard.TargetProperty="Opacity"
                                                                     Duration="0:0:0.3" To="{TemplateBinding HintOpacity}"
                                                                     EasingFunction="{StaticResource AnimationEasingFunction}"/>
                                                    <DoubleAnimation Storyboard.TargetName="ScaleHost"  Storyboard.TargetProperty="Scale"
                                                                     Duration="0:0:0.3" To="1"
                                                                     EasingFunction="{StaticResource AnimationEasingFunction}"/>
                                                </Storyboard>
                                            </VisualTransition>
                                            <VisualTransition From="*" To="HintRestingPosition">
                                                <Storyboard>
                                                    <DoubleAnimation Storyboard.TargetName="FloatingHintTextBlock" Storyboard.TargetProperty="Opacity"
                                                                     Duration="0:0:0.3"
                                                                     EasingFunction="{StaticResource AnimationEasingFunction}"/>
                                                    <DoubleAnimation Storyboard.TargetName="ScaleHost"  Storyboard.TargetProperty="Scale"
                                                                     Duration="0:0:0.3"
                                                                     EasingFunction="{StaticResource AnimationEasingFunction}"/>
                                                </Storyboard>
                                            </VisualTransition>
                                        </VisualStateGroup.Transitions>
                                        <VisualState x:Name="HintFloatingPosition">
                                            <Storyboard>
                                                <DoubleAnimation Storyboard.TargetProperty="Opacity" Storyboard.TargetName="FloatingHintTextBlock"
                                                                 Duration="0" To="{TemplateBinding HintOpacity}" />
                                                <DoubleAnimation Storyboard.TargetName="ScaleHost"  Storyboard.TargetProperty="Scale"
                                                                 Duration="0" To="1"/>
                                            </Storyboard>
                                        </VisualState>
                                        <VisualState x:Name="HintRestingPosition">
                                            <Storyboard>
                                                <DoubleAnimation Storyboard.TargetProperty="Opacity" Storyboard.TargetName="FloatingHintTextBlock"
                                                                 Duration="0" />
                                                <DoubleAnimation Storyboard.TargetName="ScaleHost"  Storyboard.TargetProperty="Scale"
                                                                 Duration="0" />
                                            </Storyboard>
                                        </VisualState>
                                    </VisualStateGroup>
                                </VisualStateManager.VisualStateGroups>
                                <wpf:ScaleHost x:Name="ScaleHost" />
                                <ContentControl x:Name="FloatingHintTextBlock"
                                        Visibility="{TemplateBinding UseFloating, Converter={StaticResource BoolToVisConverter}}"
                                        Content="{Binding Path=Hint, RelativeSource={RelativeSource TemplatedParent}, UpdateSourceTrigger=PropertyChanged}"
                                        FontSize="{TemplateBinding FontSize}"
                                        HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                        VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                        Opacity="{TemplateBinding HintOpacity}"
                                        IsHitTestVisible="False"
                                        IsTabStop="False"
                                        RenderTransformOrigin="0,1">
                                    <ContentControl.Tag>
                                        <system:Double>0.0</system:Double>
                                    </ContentControl.Tag>
                                    <ContentControl.LayoutTransform>
                                        <TransformGroup>
                                            <ScaleTransform>
                                                <ScaleTransform.ScaleX>
                                                    <MultiBinding Converter="{StaticResource RangePositionConverter}">
                                                        <Binding Path="Scale" ElementName="ScaleHost"/>
                                                        <Binding Path="FloatingScale" RelativeSource="{RelativeSource TemplatedParent}"/>
                                                        <Binding Source="{StaticResource NoContentFloatingScale}"/>
                                                    </MultiBinding>
                                                </ScaleTransform.ScaleX>
                                                <ScaleTransform.ScaleY>
                                                    <MultiBinding Converter="{StaticResource RangePositionConverter}">
                                                        <Binding Path="Scale" ElementName="ScaleHost"/>
                                                        <Binding Path="FloatingScale" RelativeSource="{RelativeSource TemplatedParent}"/>
                                                        <Binding Source="{StaticResource NoContentFloatingScale}"/>
                                                    </MultiBinding>
                                                </ScaleTransform.ScaleY>
                                            </ScaleTransform>
                                        </TransformGroup>
                                    </ContentControl.LayoutTransform>
                                    <ContentControl.RenderTransform>
                                        <TransformGroup>
                                            <TranslateTransform>
                                                <TranslateTransform.X>
                                                    <MultiBinding Converter="{StaticResource TranslateConverter}">
                                                        <Binding Path="Scale" ElementName="ScaleHost"/>
                                                        <Binding Path="FloatingOffset.X" RelativeSource="{RelativeSource TemplatedParent}"/>
                                                    </MultiBinding>
                                                </TranslateTransform.X>
                                                <TranslateTransform.Y>
                                                    <MultiBinding Converter="{StaticResource TranslateConverter}">
                                                        <Binding Path="Scale" ElementName="ScaleHost"/>
                                                        <Binding Path="FloatingOffset.Y" RelativeSource="{RelativeSource TemplatedParent}"/>
                                                    </MultiBinding>
                                                </TranslateTransform.Y>
                                            </TranslateTransform>
                                        </TransformGroup>
                                    </ContentControl.RenderTransform>
                                </ContentControl>
                            </Grid>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Trigger>
        </Style.Triggers>
    </Style>
    
</ResourceDictionary>